package com.tdam2011.grupo05.control.notification;

import com.tdam2011.grupo05.R;
import com.tdam2011.grupo05.ui.activities.DashboardActivity;
import com.tdam2011.grupo05.ui.activities.message.MessageWebActivity;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

@SuppressWarnings("unused")
public class NotificationNetwork extends AbstractNotification {

	private static String message = "";
	private static final int NETWORK = 1;
	private static final int NETWORK_WIFI = 1;
	private static final int NETWORK_MOBILE = 2;
	private static final int NETWORK_NO_CONNECTION = 3;

	public static void notifyDisconnected(Context context, String m) {
		message = m;
		Notification notification = getNotification(context,
				NETWORK_NO_CONNECTION);
		getManager(context).notify(NETWORK, notification);
	}

	public static void notifyMobileConnected(Context context, String m) {
		message = m;
		Notification notification = getNotification(context, NETWORK_MOBILE);
		getManager(context).notify(NETWORK, notification);
	}

	public static void notifyWifiConnected(Context context, String m) {
		message = m;
		Notification notification = getNotification(context, NETWORK_WIFI);
		getManager(context).notify(NETWORK, notification);
	}

	private static Notification getNotification(Context context, int option) {
		Notification notification = null;
		PendingIntent pIntent = null;
		Intent intent = new Intent();
		intent.setComponent(new ComponentName(context.getPackageName(),
				DashboardActivity.class.getName()));
		switch (option) {
		case NETWORK_WIFI:
			notification = new Notification(R.drawable.ic_action_config,
					message, System.currentTimeMillis());
			pIntent = PendingIntent.getActivity(context, NETWORK_WIFI, intent,
					PendingIntent.PARCELABLE_WRITE_RETURN_VALUE);
			notification.setLatestEventInfo(
					context,
					context.getResources().getString(
							R.string.notification_network_wifi),
					context.getResources().getString(
							R.string.notification_network_service_enable),
					pIntent);

			break;
		case NETWORK_MOBILE:
			notification = new Notification(R.drawable.ic_action_config,
					message, System.currentTimeMillis());
			pIntent = PendingIntent.getActivity(context, NETWORK_MOBILE,
					intent, PendingIntent.PARCELABLE_WRITE_RETURN_VALUE);
			notification.setLatestEventInfo(
					context,
					context.getResources().getString(
							R.string.notification_network_mobile),
					context.getResources().getString(
							R.string.notification_network_service_enable),
					pIntent);

			break;
		case NETWORK_NO_CONNECTION:
			notification = new Notification(R.drawable.ic_no_connection,
					message, System.currentTimeMillis());
			pIntent = PendingIntent.getActivity(context, NETWORK_NO_CONNECTION,
					intent, PendingIntent.PARCELABLE_WRITE_RETURN_VALUE);
			notification.setLatestEventInfo(
					context,
					context.getResources().getString(
							R.string.notification_network_disconnected),
					context.getResources().getString(
							R.string.notification_network_service_disable),
					pIntent);

			break;

		default:
			throw new UnknownError("unkonw option");
		}
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		return notification;
	}
}
